<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>事件Dom与Bom | 凯的个人博客</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/favicon.ico">
    <meta name="description" content="blog">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/assets/css/0.styles.1299ef83.css" as="style"><link rel="preload" href="/assets/js/app.ba7d257b.js" as="script"><link rel="preload" href="/assets/js/3.018f6450.js" as="script"><link rel="preload" href="/assets/js/1.7b7c57c8.js" as="script"><link rel="preload" href="/assets/js/22.c0fc1edc.js" as="script"><link rel="prefetch" href="/assets/js/10.fde56a2d.js"><link rel="prefetch" href="/assets/js/11.8c4e5f05.js"><link rel="prefetch" href="/assets/js/12.e3c30c69.js"><link rel="prefetch" href="/assets/js/13.8229d868.js"><link rel="prefetch" href="/assets/js/14.32869bf0.js"><link rel="prefetch" href="/assets/js/15.2263ef4b.js"><link rel="prefetch" href="/assets/js/16.2ab685d2.js"><link rel="prefetch" href="/assets/js/17.e2acf9c8.js"><link rel="prefetch" href="/assets/js/18.7dfc157d.js"><link rel="prefetch" href="/assets/js/19.d1da7e7c.js"><link rel="prefetch" href="/assets/js/20.e23c5514.js"><link rel="prefetch" href="/assets/js/21.9dd252a6.js"><link rel="prefetch" href="/assets/js/23.68b6a1ef.js"><link rel="prefetch" href="/assets/js/24.cdb5a0a0.js"><link rel="prefetch" href="/assets/js/25.4c09c358.js"><link rel="prefetch" href="/assets/js/26.a9096ca6.js"><link rel="prefetch" href="/assets/js/27.13a75237.js"><link rel="prefetch" href="/assets/js/28.33bdb258.js"><link rel="prefetch" href="/assets/js/29.74801f15.js"><link rel="prefetch" href="/assets/js/30.30b419c0.js"><link rel="prefetch" href="/assets/js/31.524f160e.js"><link rel="prefetch" href="/assets/js/32.9c5d3891.js"><link rel="prefetch" href="/assets/js/33.9070a57a.js"><link rel="prefetch" href="/assets/js/34.d27b9d35.js"><link rel="prefetch" href="/assets/js/35.3f94918e.js"><link rel="prefetch" href="/assets/js/36.3ec7537c.js"><link rel="prefetch" href="/assets/js/37.087a17ad.js"><link rel="prefetch" href="/assets/js/38.e79a060b.js"><link rel="prefetch" href="/assets/js/39.219f3fef.js"><link rel="prefetch" href="/assets/js/4.9a7e3e1b.js"><link rel="prefetch" href="/assets/js/40.dc82901c.js"><link rel="prefetch" href="/assets/js/41.e98ec0ac.js"><link rel="prefetch" href="/assets/js/42.96575cb1.js"><link rel="prefetch" href="/assets/js/43.e0bb13d9.js"><link rel="prefetch" href="/assets/js/44.7ee919e9.js"><link rel="prefetch" href="/assets/js/45.65f8d6dd.js"><link rel="prefetch" href="/assets/js/46.70530ec4.js"><link rel="prefetch" href="/assets/js/47.35587fbc.js"><link rel="prefetch" href="/assets/js/48.a6fdae9d.js"><link rel="prefetch" href="/assets/js/49.f369ed81.js"><link rel="prefetch" href="/assets/js/5.87035e91.js"><link rel="prefetch" href="/assets/js/50.519b62e3.js"><link rel="prefetch" href="/assets/js/51.38baa29a.js"><link rel="prefetch" href="/assets/js/6.74d67ffd.js"><link rel="prefetch" href="/assets/js/7.4c822714.js"><link rel="prefetch" href="/assets/js/8.69f56ef7.js"><link rel="prefetch" href="/assets/js/9.dec685f7.js">
    <link rel="stylesheet" href="/assets/css/0.styles.1299ef83.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-7dd95ae2><div data-v-7dd95ae2><div class="password-shadow password-wrapper-out" style="display:none;" data-v-59e6cb88 data-v-7dd95ae2 data-v-7dd95ae2><h3 class="title" data-v-59e6cb88>凯的个人博客</h3> <p class="description" data-v-59e6cb88>blog</p> <label id="box" class="inputBox" data-v-59e6cb88><input type="password" value="" data-v-59e6cb88> <span data-v-59e6cb88>Konck! Knock!</span> <button data-v-59e6cb88>OK</button></label> <div class="footer" data-v-59e6cb88><span data-v-59e6cb88><i class="iconfont reco-theme" data-v-59e6cb88></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59e6cb88>vuePress-theme-reco</a></span> <span data-v-59e6cb88><i class="iconfont reco-copyright" data-v-59e6cb88></i> <a data-v-59e6cb88><span data-v-59e6cb88>凯</span>
          
        <!---->
        2024
      </a></span></div></div> <div class="hide" data-v-7dd95ae2><header class="navbar" data-v-7dd95ae2><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/logo.jpg" alt="凯的个人博客" class="logo"> <span class="site-name">凯的个人博客</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      前端技术
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/css/" class="nav-link"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/categories/js/" class="nav-link"><i class="undefined"></i>
  js
</a></li><li class="dropdown-item"><!----> <a href="/categories/html/" class="nav-link"><i class="undefined"></i>
  html
</a></li><li class="dropdown-item"><!----> <a href="/categories/react/" class="nav-link"><i class="undefined"></i>
  react
</a></li><li class="dropdown-item"><!----> <a href="/categories/ts/" class="nav-link"><i class="undefined"></i>
  ts
</a></li><li class="dropdown-item"><!----> <a href="/categories/微信小程序/" class="nav-link"><i class="undefined"></i>
  微信小程序
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  Tag
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      消息栏
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/theme-reco/" class="nav-link"><i class="undefined"></i>
  vuepress-reco
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      github链接
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/recoluan" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-7dd95ae2></div> <aside class="sidebar" data-v-7dd95ae2><div class="personal-info-wrapper" data-v-210250cf data-v-7dd95ae2><img src="/avatar.jpg" alt="author-avatar" class="personal-img" data-v-210250cf> <h3 class="name" data-v-210250cf>
    凯
  </h3> <div class="num" data-v-210250cf><div data-v-210250cf><h3 data-v-210250cf>40</h3> <h6 data-v-210250cf>文章</h6></div> <div data-v-210250cf><h3 data-v-210250cf>6</h3> <h6 data-v-210250cf>分类</h6></div></div> <ul class="social-links" data-v-210250cf></ul> <hr data-v-210250cf></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      前端技术
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/css/" class="nav-link"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/categories/js/" class="nav-link"><i class="undefined"></i>
  js
</a></li><li class="dropdown-item"><!----> <a href="/categories/html/" class="nav-link"><i class="undefined"></i>
  html
</a></li><li class="dropdown-item"><!----> <a href="/categories/react/" class="nav-link"><i class="undefined"></i>
  react
</a></li><li class="dropdown-item"><!----> <a href="/categories/ts/" class="nav-link"><i class="undefined"></i>
  ts
</a></li><li class="dropdown-item"><!----> <a href="/categories/微信小程序/" class="nav-link"><i class="undefined"></i>
  微信小程序
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  Tag
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      消息栏
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/theme-reco/" class="nav-link"><i class="undefined"></i>
  vuepress-reco
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      github链接
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/recoluan" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <ul class="sidebar-links"><li><a href="/blogs/Front/js/01-js基础.html" class="sidebar-link">js基础</a></li><li><a href="/blogs/Front/js/02-js语法.html" class="sidebar-link">js语法</a></li><li><a href="/blogs/Front/js/03-js数学方法.html" class="sidebar-link">js数学方法</a></li><li><a href="/blogs/Front/js/04-js数组进阶.html" class="sidebar-link">js数组进阶</a></li><li><a href="/blogs/Front/js/05-day.js第三方时间插件.html" class="sidebar-link">day.js第三方时间插件</a></li><li><a href="/blogs/Front/js/06-js事件.html" class="sidebar-link">js事件</a></li><li><a href="/blogs/Front/js/07-事件Dom与Bom.html" class="active sidebar-link">事件Dom与Bom</a></li><li><a href="/blogs/Front/js/08-Ajax网络请求.html" class="sidebar-link">Ajax 网络请求</a></li><li><a href="/blogs/Front/js/09-ajax封装与应用.html" class="sidebar-link">ajax 封装与应用</a></li><li><a href="/blogs/Front/js/10-git操作与项目管理.html" class="sidebar-link">git操作与项目管理</a></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-59e6cb88 data-v-7dd95ae2><h3 class="title" data-v-59e6cb88>事件Dom与Bom</h3> <!----> <label id="box" class="inputBox" data-v-59e6cb88><input type="password" value="" data-v-59e6cb88> <span data-v-59e6cb88>Konck! Knock!</span> <button data-v-59e6cb88>OK</button></label> <div class="footer" data-v-59e6cb88><span data-v-59e6cb88><i class="iconfont reco-theme" data-v-59e6cb88></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59e6cb88>vuePress-theme-reco</a></span> <span data-v-59e6cb88><i class="iconfont reco-copyright" data-v-59e6cb88></i> <a data-v-59e6cb88><span data-v-59e6cb88>凯</span>
          
        <!---->
        2024
      </a></span></div></div> <div data-v-7dd95ae2><div data-v-7dd95ae2><main class="page" style="padding-right:0;"><section style="display:;"><div class="page-title"><h1 class="title">事件Dom与Bom</h1> <div data-v-8a445198><i class="iconfont reco-account" data-v-8a445198><span data-v-8a445198>凯</span></i> <i class="iconfont reco-date" data-v-8a445198><span data-v-8a445198>4/30/2024</span></i> <!----> <i class="tags iconfont reco-tag" data-v-8a445198><span class="tag-item" data-v-8a445198>js</span></i></div></div> <div class="theme-reco-content content__default"><h1 id="dom与bom"><a href="#dom与bom" class="header-anchor">#</a> Dom与Bom</h1> <ul><li>window 对象</li> <li>window 全局对象</li> <li>Dom</li> <li>Bom</li></ul> <h2 id="_1-window-对象"><a href="#_1-window-对象" class="header-anchor">#</a> 1.window 对象</h2> <blockquote><p>在js 中 有一个全局对象，整个对象拥有浏览器和页面DOM树所有的操作方法</p> <p>window 自身带有一些全局方法：定时器 setInterval      延时器 setTimeout</p> <p>window。document   文档对象--DOM操作对象</p> <p>BOM对象：window.location 浏览器地址栏      window.history浏览器历史记录     window.screw  浏览器屏幕对象</p></blockquote> <h3 id="定时器"><a href="#定时器" class="header-anchor">#</a> 定时器</h3> <p>创建定时器</p> <blockquote><p>没间隔 1s 执行一次函数体</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> timer <span class="token operator">=</span> window<span class="token punctuation">.</span><span class="token function">setInterval</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    
<span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token number">1000</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>案例    倒计时发送验证码</p> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>body</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span><span class="token punctuation">&gt;</span></span>发送验证码<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
        <span class="token keyword">let</span> btn <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'button'</span><span class="token punctuation">)</span>
        btn<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'click'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">let</span> count <span class="token operator">=</span> <span class="token number">10</span>
            <span class="token keyword">let</span> timer <span class="token operator">=</span> <span class="token function">setInterval</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                count<span class="token operator">--</span><span class="token punctuation">;</span> 
                <span class="token keyword">if</span> <span class="token punctuation">(</span>count <span class="token operator">&gt;</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    btn<span class="token punctuation">.</span>textContent <span class="token operator">=</span> count <span class="token operator">+</span> <span class="token string">'后重新发送'</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
                    <span class="token function">clearInterval</span><span class="token punctuation">(</span>timer<span class="token punctuation">)</span><span class="token punctuation">;</span> 
                    btn<span class="token punctuation">.</span>textContent <span class="token operator">=</span> <span class="token string">'发送验证码'</span><span class="token punctuation">;</span> 
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">1000</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span>
    </span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>body</span><span class="token punctuation">&gt;</span></span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><h3 id="事件的清除与重新绑定-【补充】"><a href="#事件的清除与重新绑定-【补充】" class="header-anchor">#</a> 事件的清除与重新绑定  【补充】</h3> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> <span class="token function-variable function">countDown</span> <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token comment">//具体事件</span>
<span class="token punctuation">}</span>
<span class="token comment">//给dom添加一个事件监听---重新</span>
dom<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'click'</span><span class="token punctuation">,</span>countDown<span class="token punctuation">)</span>
<span class="token comment">//清除这个dom的事件监听</span>
dom<span class="token punctuation">.</span><span class="token function">removeEventListener</span><span class="token punctuation">(</span><span class="token string">'click'</span><span class="token punctuation">,</span><span class="token keyword">null</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><ul><li>倒计时 验证码 完整代码</li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code>        <span class="token keyword">let</span> btn <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'button'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">const</span> <span class="token function-variable function">countDown</span> <span class="token operator">=</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'点了一次'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment">// 每间隔1s 10 累减 输出</span>
            <span class="token keyword">let</span> num <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
            <span class="token keyword">let</span> timer <span class="token operator">=</span> window<span class="token punctuation">.</span><span class="token function">setInterval</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                num<span class="token operator">--</span><span class="token punctuation">;</span>
                btn<span class="token punctuation">.</span>innerText <span class="token operator">=</span> num <span class="token operator">+</span> <span class="token string">'s后重新获取'</span>
                <span class="token comment">// 如果num ==0,停止定时器</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>num <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token comment">// 清除定时器</span>
                    window<span class="token punctuation">.</span><span class="token function">clearInterval</span><span class="token punctuation">(</span>timer<span class="token punctuation">)</span>
                    <span class="token comment">// 设置按钮的文本</span>
                    btn<span class="token punctuation">.</span>innerText <span class="token operator">=</span> <span class="token string">'发送验证码'</span>
                    <span class="token comment">// 重新给这个按钮添加事件--点了之后 又可以进行倒计时</span>
                    btn<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'click'</span><span class="token punctuation">,</span>countDown <span class="token punctuation">)</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">1000</span><span class="token punctuation">)</span>
            <span class="token comment">// 清除自身的点击事件</span>
            btn<span class="token punctuation">.</span><span class="token function">removeEventListener</span><span class="token punctuation">(</span><span class="token string">'click'</span><span class="token punctuation">,</span>countDown<span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
        btn<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'click'</span><span class="token punctuation">,</span>countDown <span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br></div></div><h4 id="延时器"><a href="#延时器" class="header-anchor">#</a> 延时器</h4> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">//创建 </span>
<span class="token keyword">let</span> timer <span class="token operator">=</span> window<span class="token punctuation">.</span><span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    
<span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token comment">//清除</span>
window<span class="token punctuation">.</span><span class="token function">clearTimeout</span><span class="token punctuation">(</span>timer<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="dom"><a href="#dom" class="header-anchor">#</a> DOM</h2> <blockquote><p>dom树操作</p> <p>dom节点的增删改查</p> <p>dom节点自身操作： 获取/修改属性  获取/修改样式   操作自身节点的内容</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code>    <span class="token comment">// 给div添加 p标签</span>
        <span class="token comment">//1.创建一个节点 追加到div的内容最后</span>
        <span class="token keyword">let</span> p <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">createElement</span><span class="token punctuation">(</span><span class="token string">'p'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// 给p添加内容</span>
        p<span class="token punctuation">.</span>innerHTML <span class="token operator">=</span> <span class="token string">'我是添加进来的内容'</span><span class="token punctuation">;</span>
        <span class="token comment">// 给p标签修改类名 </span>
        <span class="token comment">// p.className = 'p1'</span>
        p<span class="token punctuation">.</span>classList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">'p1'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        p<span class="token punctuation">.</span>id <span class="token operator">=</span> <span class="token string">'aa'</span><span class="token punctuation">;</span>
        p<span class="token punctuation">.</span>dataset<span class="token punctuation">[</span><span class="token string">'xxxx'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">1000</span><span class="token punctuation">;</span>
        p<span class="token punctuation">.</span>style<span class="token punctuation">.</span>color<span class="token operator">=</span><span class="token string">&quot;#f44&quot;</span>

        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>p<span class="token punctuation">)</span><span class="token punctuation">;</span>
        document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'div'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">appendChild</span><span class="token punctuation">(</span>p<span class="token punctuation">)</span><span class="token punctuation">;</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code> <span class="token comment">// 2.通过innerHTML 直接覆盖赋值 给div的内容修改</span>
        document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'div'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>innerHTML<span class="token operator">=</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">
            &lt;p id=&quot;aa&quot; style=&quot;color:#f44&quot; data-xxx=&quot;1000&quot; class=&quot;p1&quot;&gt; 我是新增的内容  &lt;/p&gt;
        </span><span class="token template-punctuation string">`</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code> <span class="token comment">// 1.获取dom</span>
        <span class="token keyword">let</span> box <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'.box'</span><span class="token punctuation">)</span>
        <span class="token comment">// 2.删除dom</span>
        box<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">//修改节点</span>
    <span class="token keyword">let</span> p <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'p'</span><span class="token punctuation">)</span>

        p<span class="token punctuation">.</span>classList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">'p1'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        p<span class="token punctuation">.</span>id <span class="token operator">=</span> <span class="token string">'aa'</span><span class="token punctuation">;</span>
        p<span class="token punctuation">.</span>dataset<span class="token punctuation">[</span><span class="token string">'xxxx'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">1000</span><span class="token punctuation">;</span>
        p<span class="token punctuation">.</span>style<span class="token punctuation">.</span>color<span class="token operator">=</span><span class="token string">&quot;#f44&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code>   <span class="token comment">// h4  4个</span>
        <span class="token keyword">let</span> p1 <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">)</span>
        <span class="token keyword">let</span> p2 <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementsByClassName</span><span class="token punctuation">(</span><span class="token string">'b'</span><span class="token punctuation">)</span>   <span class="token comment">// 类名获取获取的是 伪数组：不能使用数组的所有内置方法 </span>
        <span class="token keyword">let</span> p3 <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementsByTagName</span><span class="token punctuation">(</span><span class="token string">'p'</span><span class="token punctuation">)</span>   <span class="token comment">//标签名获取 伪数组</span>
        <span class="token keyword">let</span> p4 <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementsByName</span><span class="token punctuation">(</span><span class="token string">'aa'</span><span class="token punctuation">)</span>     <span class="token comment">// 根据name属性获取 nodelist伪数组 可以用数组的forEach map</span>


        <span class="token comment">// h5  2个</span>
        <span class="token keyword">let</span> p5 <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'p'</span><span class="token punctuation">)</span>  <span class="token comment">//根据选择器获取 满足匹配选择器的第一个元素</span>
        <span class="token keyword">let</span> p6 <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">querySelectorAll</span><span class="token punctuation">(</span><span class="token string">'p'</span><span class="token punctuation">)</span> <span class="token comment">//根据选择器获取 满足匹配选择器的所有元素组成的 nodelist伪数组</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>p5<span class="token punctuation">)</span><span class="token punctuation">;</span> 
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>p6<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="bom"><a href="#bom" class="header-anchor">#</a> BOM</h2> <h3 id="location-浏览器地址栏"><a href="#location-浏览器地址栏" class="header-anchor">#</a> location 浏览器地址栏</h3> <blockquote><p>获取 浏览器地址栏信息</p> <p>可以实现页面跳转</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code> search：<span class="token string">&quot;?id=1000&amp;name=zhangsan&quot;</span>     #获取网页的数据 <span class="token operator">?</span>key<span class="token operator">=</span>val<span class="token operator">&amp;</span>key1<span class="token operator">=</span>val1
<span class="token literal-property property">hash</span><span class="token operator">:</span> <span class="token string">&quot;#a&quot;</span>    #页面当前展示的 盒子区域，可以快速展示显示 到某个盒子  匹配是根据id名匹配
<span class="token literal-property property">host</span><span class="token operator">:</span> <span class="token string">&quot;127.0.0.1:5500&quot;</span>   #域名<span class="token operator">/</span>ip <span class="token operator">+</span> 端口号
<span class="token literal-property property">href</span><span class="token operator">:</span> <span class="token string">&quot;http://127.0.0.1:5500/04-BOm-location.html#a&quot;</span>    #当前完整的网址
<span class="token literal-property property">protocol</span><span class="token operator">:</span> <span class="token string">&quot;http:&quot;</span>       #协议
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code>location<span class="token punctuation">.</span><span class="token function">reload</span><span class="token punctuation">(</span><span class="token punctuation">)</span>   <span class="token comment">//重载当前网页  刷新</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code>location<span class="token punctuation">.</span>href <span class="token operator">=</span> <span class="token string">'新的网页链接'</span>   <span class="token comment">//跳转网页</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>将search 转换为 一个对象</li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code> location<span class="token punctuation">.</span>search：<span class="token string">&quot;?id=1000&amp;name=zhangsan&quot;</span> 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">//&quot;?id=1000&amp;name=zhangsan&quot;    ===&gt; {id:1000,name:zhangsan}</span>

<span class="token keyword">function</span> <span class="token function">formatSearch</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="history-历史记录"><a href="#history-历史记录" class="header-anchor">#</a> history 历史记录</h3> <div class="language-js line-numbers-mode"><pre class="language-js"><code>history<span class="token punctuation">.</span><span class="token function">forward</span><span class="token punctuation">(</span><span class="token punctuation">)</span>   #前进一页
history<span class="token punctuation">.</span><span class="token function">back</span><span class="token punctuation">(</span><span class="token punctuation">)</span>  #后退一页
history<span class="token punctuation">.</span><span class="token function">go</span><span class="token punctuation">(</span>数字<span class="token punctuation">)</span>  #前进后退 对应页数  数字<span class="token operator">&gt;</span><span class="token number">0</span> 表示前进几页    数字<span class="token operator">&lt;</span><span class="token number">0</span> 后退几页  数字<span class="token operator">=</span><span class="token number">0</span> 刷新网页
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="screen-屏幕对象"><a href="#screen-屏幕对象" class="header-anchor">#</a> Screen 屏幕对象</h3> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token literal-property property">availHeight</span><span class="token operator">:</span> <span class="token number">1040</span>    #屏幕可用高度
<span class="token literal-property property">availWidth</span><span class="token operator">:</span> <span class="token number">1920</span>    #屏幕可用宽度

<span class="token literal-property property">height</span><span class="token operator">:</span> <span class="token number">1080</span>   #屏幕总高度  （多的40px 是windows 桌面状态栏 最下面的 ）
<span class="token literal-property property">width</span><span class="token operator">:</span> <span class="token number">1920</span>   #屏幕总宽度
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="navigator-浏览器版本信息"><a href="#navigator-浏览器版本信息" class="header-anchor">#</a> navigator 浏览器版本信息</h3> <blockquote><p>获取当前的浏览器版本信息 和兼容信息</p> <p>获取用户的地址信息（浏览器自带 ）<code>navigatior.geolocation.getcurrentPosition()</code></p> <p>​														  请求的响应服务器 是 浏览器的厂商 ，谷歌服务器（有墙）</p></blockquote> <h2 id="面试题"><a href="#面试题" class="header-anchor">#</a> 面试题：</h2> <ul><li>HTTP 和 https 的区别</li></ul> <blockquote><p>http端口：80    和 https端口：443   都是超文本传输协议，都可以用在前端浏览器 请求数据上，都是 基于TCP网络通信协议的子协议</p> <p>HTTPS 的 S代表： SSL 数字安全证书</p> <p>​        SSL: 全球公认的做网络通信加密的机构，定义一种通信传输数据过程中定义的加密规则（公钥 私钥：随时随地随机在变的），网站可以配置SSL数字安全证书，在网络通信过程中 会自动将数据进行加密再发送。  SSL颁发机构有很多，SSL 可以用免费的 也可以用收费的，SSL证书里面存储的就是 公钥信息</p></blockquote> <h3 id="作业-20-30-分钟"><a href="#作业-20-30-分钟" class="header-anchor">#</a> 作业：  20-30 分钟</h3> <p>轮播图片：
三张图进行轮播，每间隔3s中 自动切换下一张
如果用户点击下一张/上一张，等待3s后 继续切下一张
如果用户鼠标 悬停 在轮播上，应该停止自动切换功能</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>swiper
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="作业-转换search"><a href="#作业-转换search" class="header-anchor">#</a> 作业：转换search</h2> <blockquote><p>功能：无论search  拿到的时候 任意个参数都可以支持</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">//&quot;?id=1000&amp;name=zhangsan&quot;    ===&gt; {id:1000,name:zhangsan}</span>

<span class="token keyword">function</span> <span class="token function">formatSearch</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="作业3-dom文档对象模型-day07-课后作业完成"><a href="#作业3-dom文档对象模型-day07-课后作业完成" class="header-anchor">#</a> 作业3： dom文档对象模型-day07 课后作业完成</h3></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">5/27/2024, 8:38:35 PM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev"><a href="/blogs/Front/js/06-js事件.html" class="prev">
          js事件
        </a></span> <span class="next"><a href="/blogs/Front/js/08-Ajax网络请求.html">
          Ajax 网络请求
        </a></span></p></div> <div class="comments-wrapper"><!----></div></main></div> <!----></div> <ul class="sub-sidebar sub-sidebar-wrapper" style="width:0;" data-v-b57cc07c data-v-7dd95ae2></ul></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-6e9c9188 data-v-6e9c9188><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-6e9c9188><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-6e9c9188></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-6e9c9188></path></svg></div><canvas id="vuepress-canvas-cursor"></canvas></div></div>
    <script src="/assets/js/app.ba7d257b.js" defer></script><script src="/assets/js/3.018f6450.js" defer></script><script src="/assets/js/1.7b7c57c8.js" defer></script><script src="/assets/js/22.c0fc1edc.js" defer></script>
  </body>
</html>
